<?php

namespace App\Http\Controllers\Swoolex;

use App\Models\Members;
use Illuminate\Http\Request;

class ChatController extends ChatBaseController
{
    /**
     * Instructions:登录
     * Author: Vijay  <1937832819@qq.com>
     * Time: 2019/2/28 11:55
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function login(Request $request)
    {
        if ($request->isMethod('post')) {
            $info = Members::where([
                'username' => $request['username'],
                'pwd' => md5($request['pwd'])
            ])->first();
            $data = [];
            if (empty($info)) {
                $this->resJson(400, '登录失败', $data);
            } else {
                $data['user_id'] = $info->id;
                $data['username'] = $info->username;
                $this->resJson(200, '发送成功', $data);
            }
        }
        $assign = [

        ];
        return view('swoolex.chat.login', $assign);
    }

    /**
     * Instructions:
     * Author: Vijay  <1937832819@qq.com>
     * Time: 2019/2/28 12:03
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index(Request $request)
    {
        $assign = [
            'username' => $request['username'],
            'user_id' => $request['user_id']
        ];
        return view('swoolex.chat.index', $assign);
    }

    /**
     * Instructions:冒泡排序
     * Author: Vijay  <1937832819@qq.com>
     * Time: 2019/3/1 13:45
     */
    public function test()
    {
        $b = [6, 3, 8, 2, 9, 1];
        $count = count($b);
        $big = $count - 1;
        for ($i = 0; $i <= $big; $i++) {
            for ($j = $big; $j > $i; $j--) {
                if ($b[$j] < $b[$j - 1]) {
                    $max = $b[$j - 1];
                    $b[$j - 1] = $b[$j];
                    $b[$j] = $max;
                }
            }
        }
        print_r($b);
    }
}
